package com.zero.zui
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.utils.Dictionary;
	
	import com.zero.zconstant.ColorConst;
	import com.zero.zsingleton.ComponentSingleton;
	import com.zero.zutils.BaseUtils;
	import com.zero.zutils.ShapeUtils;
	import com.zero.zutils.UiUtils;
	
	public class ShapeButton extends SimpleButton
	{
		private static const Z_WIDTH:String				= "Z_WIDTH";
		private static const Z_HEIGHT:String				= "Z_HEIGHT";
		private static const Z_UP_STATE_COLOR:String		= "Z_UP_STATE_COLOR";
		private static const Z_DOWN_STATE_COLOR:String 	= "Z_DOWN_STATE_COLOR";
		private static const Z_OVER_STATE_COLOR:String	= "Z_OVER_STATE_COLOR";
		private static const Z_BORDER_COLOR:String 		= "Z_BORDER_COLOR";
		
		private var _downStateShape	:Shape;
		private var _overStateShape	:Shape;
		private var _upStateShape		:Shape;
		private var _downStateColor	:uint;
		private var _overStateColor	:uint;
		private var _upStateColor		:uint;
		private var _borderColor		:uint;
		
		private var _width				:int;
		private var _height			:int;
		
		private var _attributeDic		:Dictionary;
		
		
		public function ShapeButton()
		{
			_attributeDic = new Dictionary();
		}
		
		override public function set width($value:Number):void
		{
			_width = $value;
			
			attributeChange(Z_WIDTH);
		}
		
		override public function set height($value:Number):void
		{
			_height = $value;
			
			attributeChange(Z_HEIGHT);
		}
		
		public function set upStateColor($value:uint):void
		{
			_upStateColor = $value;
			
			attributeChange(Z_UP_STATE_COLOR);
		}
		
		public function set downStateColor($value:uint):void
		{
			_downStateColor = $value;
			
			attributeChange(Z_DOWN_STATE_COLOR);
		}
		
		public function set overStateColor($value:uint):void
		{
			_overStateColor = $value;
			
			attributeChange(Z_OVER_STATE_COLOR);
		}
		
		public function set borderColor($value:uint):void
		{
			_borderColor = $value;
			
			attributeChange(Z_BORDER_COLOR);
		}
		
		protected function attributeChange($styleName:String):void
		{
			_attributeDic[$styleName] = true;
			attributeUpdate();
			addChildren();
		}
		
		protected function attributeUpdate():void
		{
			if(_attributeDic[Z_WIDTH] && _attributeDic[Z_HEIGHT])
			{
				_upStateColor 	= BaseUtils.setObject(_upStateColor, ColorConst.LIGHT_GRAY);
				upState 		= ShapeUtils.drawRect(_upStateShape, _upStateColor, _width, _height, _borderColor);
			}
			if(_attributeDic[Z_WIDTH] && _attributeDic[Z_HEIGHT])
			{
				_downStateColor = BaseUtils.setObject(_downStateColor, ColorConst.LIGHT_GRAY);
				downState 		= ShapeUtils.drawRect(_downStateShape, _downStateColor, _width, _height, _borderColor);
			}
			if(_attributeDic[Z_WIDTH] && _attributeDic[Z_HEIGHT])
			{
				_overStateColor = BaseUtils.setObject(_overStateColor, ColorConst.GRAY);
				overState 		= ShapeUtils.drawRect(_overStateShape, _overStateColor, _width, _height, _borderColor);
				hitTestState 	= overState;
			}
		}
		
		protected function addChildren():void
		{
		
		}
	}
}